1   /*
2    * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
3    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4    *
5    * This code is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU General Public License version 2 only, as
7    * published by the Free Software Foundation.
8    *
9    * This code is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11   * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12   * version 2 for more details (a copy is included in the LICENSE file that
13   * accompanied this code).
14   *
15   * You should have received a copy of the GNU General Public License version
16   * 2 along with this work; if not, write to the Free Software Foundation,
17   * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18   *
19   * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20   * or visit www.oracle.com if you need additional information or have any
21   * questions.
22   */
23  
24  /**
25   * See ClassnameCharTest.sh for details.
26   */
27  
28  import java.io.*;
29  import java.net.*;
30  import java.security.*;
31  import sun.applet.AppletClassLoader;
32  
33  public class ClassnameCharTest implements HttpCallback {
34      private static String FNPrefix;
35      private String[] respBody = new String[52];
36      private byte[][] bufs = new byte[52][8*1024];
37      private static MessageDigest md5;
38      private static byte[] file1Mac, file2Mac;
39      public void request (HttpTransaction req) {
40          try {
41              String filename = req.getRequestURI().getPath();
42              System.out.println("getRequestURI = "+req.getRequestURI());
43              System.out.println("filename = "+filename);
44              FileInputStream fis = new FileInputStream(FNPrefix+filename);
45              req.setResponseEntityBody(fis);
46              req.sendResponse(200, "OK");
47              req.orderlyClose();
48          } catch (IOException e) {
49              e.printStackTrace();
50          }
51      }
52      static HttpServer server;
53  
54      public static void test () throws Exception {
55          try {
56  
57              FNPrefix = System.getProperty("test.classes", ".")+"/";
58              server = new HttpServer (new ClassnameCharTest(), 1, 10, 0);
59              System.out.println ("Server: listening on port: " + server.getLocalPort());
60              URL base = new URL("http://localhost:"+server.getLocalPort());
61              MyAppletClassLoader acl = new MyAppletClassLoader(base);
62              Class class1 = acl.findClass("fo o");
63              System.out.println("class1 = "+class1);
64              // can't test the following class unless platform in unicode locale
65              // Class class2 = acl.findClass("\u624b\u518c");
66              // System.out.println("class2 = "+class2);
67          } catch (Exception e) {
68              if (server != null) {
69                  server.terminate();
70              }
71              throw e;
72          }
73  
74          server.terminate();
75      }
76  
77      public static void main(String[] args) throws Exception {
78          test();
79      }
80  
81      public static void except (String s) {
82          server.terminate();
83          throw new RuntimeException (s);
84      }
85  }
86  
87  class MyAppletClassLoader extends AppletClassLoader {
88      MyAppletClassLoader(URL base) {
89          super(base);
90      }
91  
92      public Class findClass(String name) throws ClassNotFoundException {
93          return super.findClass(name);
94      }
95  }